import java.util.*;

public class ProcessControlBlockTable {
	private ArrayList<ProcessControlBlock> m_pcbs;

	// Constructors
	//
	public ProcessControlBlockTable() {
		m_pcbs = new ArrayList<ProcessControlBlock>();
	}

	//
	// Accessors
	//
	public int getNumberOfProcesses(){
		return this.m_pcbs.size();
	}
	
	public ProcessControlBlock find(Process process) {
		ProcessControlBlock pcb = null;
		for (ProcessControlBlock p : m_pcbs) {
			if (process == p.getProcess()) {
				pcb = p;
				break;
			}
		}
		return pcb;
	}

	public int getProcessId(Process process) {
		ProcessControlBlock pcb = find(process);
		return m_pcbs.indexOf(pcb);
	}	
	
	public ArrayList<ProcessBookkeeping> getProcessesBookkeeping(){
		ArrayList<ProcessBookkeeping> bookkeeping = new ArrayList<ProcessBookkeeping>();
		
		for(ProcessControlBlock pcb: m_pcbs){
			bookkeeping.add(pcb.getBookkeeping());
		}
		
		return bookkeeping;
	}

	//
	// Mutators
	//
	public ProcessControlBlock add(Process process) {
		ProcessControlBlock pcb = new ProcessControlBlock(process);
		m_pcbs.add(pcb);
		return pcb;
	}
	
	public void updateAllPCBs() {
		for(ProcessControlBlock thisProcessControlBlock: this.m_pcbs){
			thisProcessControlBlock.updatePCB();
		}
	}
}
